package com.olddriver.crm.service.impl;

import com.olddriver.crm.domain.Mechanism;
import com.olddriver.crm.mapper.MechanismMapper;
import com.olddriver.crm.page.PageResult;
import com.olddriver.crm.query.MechanismQueryObject;
import com.olddriver.crm.service.IMechanismService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * Created by 季节 on 2017/12/4
 */
@Service
public class MechanismServiceImpl implements IMechanismService{

    @Autowired
    private MechanismMapper mechanismMapper;

    @Override
    public int insert(Mechanism record) {
        return mechanismMapper.insert(record);
    }

    @Override
    public Mechanism selectByPrimaryKey(Long id) {
        return mechanismMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Mechanism> selectAll() {
        return mechanismMapper.selectAll();
    }

    @Override
    public int updateByPrimaryKey(Mechanism record) {
        return mechanismMapper.updateByPrimaryKey(record);
    }

    @Override
    public PageResult query(MechanismQueryObject qo) {
        int total = mechanismMapper.queryForTotal(qo);
        if(total == 0){
            return  new PageResult(total, Collections.emptyList());
        }
        return new PageResult(total,mechanismMapper.queryForRows(qo));
    }

    @Override
    public void changeState(Long id) {
        mechanismMapper.changeState(id);
    }
}
